
//
//  ZXZHomeStatusViewModel.swift
//  up_learnWB
//
//  Created by Mac on 16/10/23.
//  Copyright © 2016年 www.ZXZ123.com. All rights reserved.
//

import Foundation


class ZXZHomeStatusViewModel {

    var showHomeArray = [ZXZHomeStatusModel]()

    func loadHomeData(isPull:isPullDid , compose:@escaping (_ isSuucess:Bool)->()){
        // 加载网络数据
        var sinceIdNum = showHomeArray.first?.id ?? 0

        var maxIdNum = ((showHomeArray.last?.id)) ?? 0
        if maxIdNum>0 {
            maxIdNum -= 1
        }

        if isPull == .DOWN {
            maxIdNum = 0
        }else{
            sinceIdNum = 0
        }


        ZXZNetworkManager.shareTools.loadListData(since_id: sinceIdNum, max_id: maxIdNum) { (data: [[String : AnyObject]]?, isSuccess:Bool) in

            if isSuccess{

                guard let array = NSArray.yy_modelArray(with: ZXZHomeStatusModel.self, json: data!) else{
                    print("数据转模型")
                    return
                }

                print("dataCount:\(data!.count)")

                //下拉刷新
                if isPull == isPullDid.DOWN{

                    self.showHomeArray =  (array as? [ZXZHomeStatusModel])! +  self.showHomeArray
                }else{
                    self.showHomeArray = self.showHomeArray + (array as? [ZXZHomeStatusModel])!
                }
                compose(true)

            }
            
        }
    }
    
    
    
    func  haha(str:String){
        print("xssxsxs\(str)")
    }
}
